//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.ml.mall.bean.page;

import java.math.BigDecimal;
import java.util.List;

/**
 * @description: 分页
 * @author kyyang
 * @date 2021/1/11 19:27
 * @version 1.0
 */
public class Page<T> {
    private int current;
    private int pageSize;
    private int total;
    private int pages;
    private List<T> records;


    public Page(Integer page, Integer pageSize) {
        this.current = 1;
        this.pageSize = 10;
        this.total = 0;
        this.pages = 1;
        if (page != null) {
            this.current = page;
        }

        if (pageSize != null) {
            this.pageSize = pageSize;
        }

    }

    public Page(Integer page, Integer pageSize, int count) {
        this(page, pageSize);
        this.setTotal(count);
    }

    public void setTotal(int count) {
        this.total = count;
        this.pages = (int) Math.ceil((double) count * 1.0D / (double) this.pageSize);
        if (this.current > this.pages) {
            this.current = this.pages;
        }

        if (this.current < 1) {
            this.current = 1;
        }

        if (this.pages < 1) {
            this.pages = 1;
        }

    }

    private int getNextPage() {
        return this.current < this.pages ? this.current + 1 : this.current;
    }

    private int getLastPage() {
        return this.current > 1 ? this.current - 1 : this.current;
    }

    public int getOffset() {
        return (this.current - 1) * this.pageSize;
    }

    public int getLimit() {
        return this.pageSize;
    }

    public int getPage() {
        return this.current;
    }

    public void setPage(int page) {
        this.current = page;
    }

    public int getPageSize() {
        return this.pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getPages() {
        return this.pages;
    }

    public void setPages(int totalPage) {
        this.pages = totalPage;
    }

    public List<T> getRecords() {
        return this.records;
    }

    public void setRecords(List<T> list) {
        this.records = list;
    }

    public int getTotal() {
        return this.total;
    }
}
